const activityApi = require('../../../services/activity');

Component({
  data: {
    wordId: 1,
    wordList: [
      {id: 1, title: '年级'},
      {id: 2, title: '题材'},
      {id: 3, title: '字数'},
      {id: 4, title: '等级'},
    ]
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      if(typeof this.getTabBar==='function'&&this.getTabBar()){
        this.getTabBar().setData({
          selected: 0
        })
      }
      // this.getList();
    },
    hide: function() {
      // 页面被隐藏
    },
    resize: function(size) {
      // 页面尺寸变化
    }
  },
  methods: {
    async composClick(e:any) {
      let {id} = e.currentTarget.dataset;
      this.setData({
        wordId: id
      })
      let res = await activityApi.typeList(id);
      console.log("res", res)
    },
    async getList() {
      let {wordId} = this.data;
      let res = await activityApi.typeList(wordId);
      console.log("res", res)
    },
    onChange(event: { detail: { name: any; }; }) {
      wx.showToast({
        title: `切换到标签 ${event.detail.name}`,
        icon: 'none',
      });
    },
    onBeforeChange(event: { detail: { callback: any; title: any; }; }) {
      const { callback, title } = event.detail;
      callback(true)
    },
    // 事件处理函数
    bindViewTap() {
      wx.navigateTo({
        url: '../logs/logs',
      })
    },
    onChooseAvatar(e: any) {
      const { avatarUrl } = e.detail
      const { nickName } = this.data.userInfo
      this.setData({
        "userInfo.avatarUrl": avatarUrl,
        hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
      })
    },
    onInputChange(e: any) {
      const nickName = e.detail.value
      const { avatarUrl } = this.data.userInfo
      this.setData({
        "userInfo.nickName": nickName,
        hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
      })
    },
    getUserProfile() {
      // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
      wx.getUserProfile({
        desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: (res) => {
          console.log(res)
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    },
  },
})
